#ifndef __I2C__AP3216C_H__
#define __I2C__AP3216C_H__
#include <linux/cdev.h>
#include <linux/i2c.h>
#include <linux/of.h> 		  // 设备树 
#include <linux/mutex.h>
#include <linux/device.h>
#include <linux/fs.h>

#define NAME "ap3216c"
#define CNT  1

#define AP3216C_RESET  0x4
#define RESET_DELAY_TIME 40
#define ALS_IR_PS_MODE 0x3

struct sys_reg {
    unsigned char sys_con;
    unsigned char int_stat;
    unsigned char int_clear;
    unsigned char ir_data_low;
    unsigned char ir_data_high;
    unsigned char als_data_low;
    unsigned char als_data_high;
    unsigned char ps_data_low;
    unsigned char ps_data_high;
};
struct als_reg {
    unsigned char con;
    unsigned char cal;
    unsigned char low_th0;   // 7-0位
    unsigned char low_th1;   // 15-8位
    unsigned char high_th0;  // 7-0位
    unsigned char high_th1;  // 15-8位
};
struct ps_reg {
    unsigned char con;
    unsigned char led_drv;
    unsigned char int_form;
    unsigned char mean_time;
    unsigned char led_wat_time;
    unsigned char cal_l;
    unsigned char cal_h;
    unsigned char low_th0;   // 2-0位
    unsigned char low_th1;   // 10-3位
    unsigned char high_th0;  // 2-0位
    unsigned char high_th1;  // 10-3位
};

struct ap3216c_cdev {
    struct cdev cdev;          // 字符设备结构体
    dev_t devno;               // 设备号
    struct class* ap3216c_class;
	struct device* ap3216c_device;
    struct sys_reg sys_addr;      // System Register Table
    struct als_reg als_addr;      // ALS Register Table
    struct ps_reg ps_addr;        // PS Register Table
    struct i2c_client* client;
    struct device_node* node;     // 设备树节点
    struct mutex mutex;  // 用于同步的互斥体
    unsigned short ir;   // 红外LED数据
    unsigned short als;  // 环境光数据
    unsigned short ps;   // 距离数据
};

#endif // __I2C__AP3216C_H__